package main

import (
	"fmt"
	"net/http"

	"github.com/gin-gonic/gin"
)

func midFunc1(c *gin.Context) {
	fmt.Println("midFunc1, start")
	c.Next()
	fmt.Println("midFunc1, end")
}

func midFunc2(c *gin.Context) {
	fmt.Println("midFunc2, start")
	c.Abort()
	fmt.Println("midFunc2, end")
}

func midFunc3(c *gin.Context) {
	fmt.Println("midFunc3, start")
	c.Next()
	fmt.Println("midFunc3, end")
}

func requestHandler(c *gin.Context) {
	fmt.Println("requestHandler, start")
	c.JSON(http.StatusOK, gin.H{
		"message": "Hello World",
	})
	fmt.Println("requestHandler, end")
}

func main() {
	r := gin.Default()
	r.GET("/index", midFunc1, midFunc2, midFunc3, requestHandler)
	r.Run(":9000")
}
